package org.teachertools.web.forms;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.teachertools.web.DateConvertUtils;
import org.teachertools.web.struts.BaseActionForm;

public class MultipleNoteForm extends BaseActionForm
{
	private static final long serialVersionUID = 6034819464695906741L;

	private java.lang.Long idCategorie;
	private java.lang.Long idMatiere;
	private java.lang.String dateNote;
	private java.lang.Long[] eleve;
	private java.lang.Long[] competence;

	public java.lang.String getDateNote()
	{
		return dateNote;
	}

	public void setDateNote(java.lang.String pDateNote)
	{
		this.dateNote = pDateNote;
	}

	public Long[] getEleve()
	{
		return eleve;
	}

	public void setEleve(Long[] pEleve)
	{
		this.eleve = pEleve;
	}

	public Long[] getCompetence()
    {
    	return this.competence;
    }

	public void setCompetence(Long[] pCompetence)
    {
    	this.competence = pCompetence;
    }

	public Long getIdCategorie()
    {
    	return this.idCategorie;
    }

	public void setIdCategorie(Long pIdCategorie)
    {
    	this.idCategorie = pIdCategorie;
    }

	public Long getIdMatiere()
    {
    	return this.idMatiere;
    }

	public void setIdMatiere(Long pIdMatiere)
    {
    	this.idMatiere = pIdMatiere;
    }

	@Override
	public void reset()
	{
		dateNote = null;
		eleve = null;
		competence = null;
		idCategorie = null;
		idMatiere = null;
	}

	@Override
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
	{
		ActionErrors errors = new ActionErrors();
		if (mapping.getPath().startsWith("/init"))
			return errors;
		if (StringUtils.isEmpty(dateNote))
		{
			errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.required",
					getMessage(request, "field.dateNote")));
		}
		else //if (StringUtils.isEmpty(dateNote) == false)
		{
			if (DateConvertUtils.parseDate(dateNote, getMessage(request, "FORMAT_DATE_COURT")) == null)
			{
				errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.wrongDate",
						getMessage(request, "field.dateNote")));
			}
		}
		return errors;
	}
}
